<?php
namespace BP\Sys;

use BP\En\EntitiesNoName;

class GloVars extends EntitiesNoName {
	protected static $_MyGloVars;	// GloVars
	public static function __staticinit() { // static class members
		self::$_MyGloVars = NULL;
	}
	public static function SetValByKey ($key, $val) // [String key, Object val]
	{
		$en = GloVar::constructor__String_Object($key, $val);
		$en->setValOfObject($val);
		return $en->Update();
	}
	public static function GetValByKeyHtml ($key) // [String key]
	{
			/* match: String */
		return $DataType->ParseText2Html(GloVars->GetValByKey_String($key));
	}
	public static function GetValByKey_String ($key) // [String key]
	{
		foreach (GloVars::getMyGloVars()->ToJavaList() as $cfg) 		{
			if ($cfg->getNo()->equals($key))
			{
				return $cfg->getVal();
			}
		}
		throw new \RuntimeException(("error key=" . $key));
	}
	public static function GetValByKey_String_String ($key, $isNullAs) // [String key, String isNullAs]
	{
		foreach (GloVars::getMyGloVars()->ToJavaList() as $cfg) 		{
			if ($cfg->getNo()->equals($key))
			{
				return $cfg->getVal();
			}
		}
		$en = GloVar::constructor__String_Object($key, $isNullAs);
		return $en->getVal();
	}
	public static function GetValByKeyInt ($key, $isNullAs) // [String key, int isNullAs]
	{
		foreach (GloVars::getMyGloVars()->ToJavaList() as $cfg) 		{
			if ($cfg->getNo()->equals($key))
			{
				return $cfg->getValOfInt();
			}
		}
		$en = GloVar::constructor__String_Object($key, $isNullAs);
		return $en->getValOfInt();
	}
	public static function GetValByKeyDecimal ($key, $isNullAs) // [String key, int isNullAs]
	{
		foreach (GloVars::getMyGloVars()->ToJavaList() as $cfg) 		{
			if ($cfg->getNo()->equals($key))
			{
				return $cfg->getValOfInt();
			}
		}
		$en = GloVar::constructor__String_Object($key, $isNullAs);
		return $en->getValOfInt();
	}
	public static function GetValByKeyBoolen ($key, $isNullAs) // [String key, boolean isNullAs]
	{
		foreach (GloVars::getMyGloVars()->ToJavaList() as $cfg) 		{
			if ($cfg->getNo()->equals($key))
			{
				return $cfg->getValOfBoolen();
			}
		}
		$val = 0;
		if ($isNullAs)
		{
			$val = 1;
		}
		$en = GloVar::constructor__String_Object($key, $val);
		return $en->getValOfBoolen();
	}
	public static function GetValByKeyFloat ($key, $isNullAs) // [String key, float isNullAs]
	{
		foreach (GloVars::getMyGloVars()->ToJavaList() as $cfg) 		{
			if ($cfg->getNo()->equals($key))
			{
				return $cfg->getValOfFloat();
			}
		}
		$en = GloVar::constructor__String_Object($key, $isNullAs);
		return $en->getValOfFloat();
	}
	public static function getMyGloVars () 
	{
		if ((self::$_MyGloVars == NULL))
		{
			self::$_MyGloVars = GloVars::constructor__();
			self::$_MyGloVars->RetrieveAll();
		}
		return self::$_MyGloVars;
	}
	public static function ReSetVal () 
	{
		self::$_MyGloVars = NULL;
	}
	public static function constructor__ () 
	{
		$me = new self();
		return $me;
	}
	public static function constructor__String ($fk_mapdata) // [String fk_mapdata]
	{
		$me = new self();
		if (SystemConfig::getIsDebug())
		{
			$me->Retrieve(FrmLineAttr::$FK_MapData, $fk_mapdata);
		}
		else
		{
			$me->RetrieveFromCash(FrmLineAttr::$FK_MapData, $fk_mapdata);
		}
		return $me;
	}
	public function getNewEntity () 
	{
		return GloVar::constructor__();
	}
	public function ToJavaList () 
	{
		return $this;
	}
	public function Tolist () 
	{
		$list = [];// 
		for ($i = 0; ($i < $this->size()); ++$i) 
		{
			$list->add($this->get($i));
		}
		return $list;
	}
}
GloVars::__staticinit(); // initialize static vars for this class on load
?>
